#!/bin/bash

## telnet localhost 9989
## ---------------------
#
#  gcc -O2 -lpthread -o SLP  TCP_serv_LPT_1.c
#
#________________________________________________

#     +----------------+
#     |17.5__12:39:45__|
#     |100:011_12+03+01|
#     +----------------+


HOST=$1
PORT=$2

HOSTEDF="127.0.0.1"
#HOSTEDF="as2"
PORTEDF="8811"

  GEO="/home/kiki/avr/crontab/diff/Etat_all.txt"
  FTEMP="/home/kiki/avr/crontab/temp_encours.txt"

#__local_DEV__:
  GEO="./Etat_all.txt"
  FTEMP="./temp_encours.txt"


#__Activer_Broadcast EDF !!!__
    #( echo "broad: pclin2 8811" ;msleep 200 ) | telnet $HOSTEDF $PORTEDF 
    ( echo "broad: $HOST $PORT" ;msleep 200 ) | telnet $HOSTEDF $PORTEDF 

#( echo "LCD: init NOW!" ; sleep  1) | telnet $HOST $PORT

A="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
A="Bilan Geothermie et Temp. "
A="B "

echo ${#A}     # Longueur
echo ${A:10:2} # Var:debut:long
for (( i=1 ; i<${#A} ; i++ )) ; do

    #echo ${A:${i}:3} # Var:debut:long
    ( echo "LCD: line:1 ${A:${i}:16}" ; msleep  200) | telnet $HOST $PORT
    msleep 50
done

# while [[ 1 == 1 ]]
for (( i=0; i<4 ; i++ ))
do

TEMP=`cat $FTEMP`
all=`cat $GEO |  awk '{print $2}' | cut -c 1-1`
#echo $all # = 1 0 0 0 1 0 = c j s n a t
c=$( echo $all | awk '{print $1}' )
j=$( echo $all | awk '{print $2}' )
s=$( echo $all | awk '{print $3}' )

n=$( echo $all | awk '{print $4}' )
a=$( echo $all | awk '{print $5}' )
t=$( echo $all | awk '{print $6}' )

   HEUR=`date '+%T'`

  (  echo "LCD: line:1 ${TEMP}   "
    msleep  200 
    echo "LCD: line:2 $c$j$s:$n$a$t" 
    msleep 400
   ) | telnet $HOST $PORT

echo "--------------WAIT 10 s________________"
sleep 10

done #while 1

echo "_______________________End"

#Command (in hex)       Effect
#-----  -----------------------------------------
#  0C   Turns ON JUST the LCD, no cursor
#  08   Turns OFF the LCD display
#  0E   Turns on the LCD display and Sets a SOLID CURSOR
#  0F   Turns on the LCD display and Sets a BLINKING CURSOR
#  80   Moves cursor to first address on the left of LINE 1
#  C0   Moves cursor to first address on the left of LINE 2
#  94   Moves cursor to first address on the left of LINE 3
#  D4   Moves cursor to first address on the left of LINE 4
